package com.huanletao.spring.aop.aop01;

import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

@Configuration
@ComponentScan("com.huanletao.spring.aop.aop01")
//@EnableAspectJAutoProxy(proxyTargetClass = true,exposeProxy = true)
public class AppConfig {

    @Bean
    public CustomMethodMatcherPointcut customMethodMatcherPointcut(){
        return new CustomMethodMatcherPointcut();
    }

    @Bean
    public DebugInterceptor debugInterceptor(){
        return new DebugInterceptor();
    }

    @Bean
    public DefaultPointcutAdvisor defaultPointcutAdvisor(CustomMethodMatcherPointcut pointcut,DebugInterceptor debugInterceptor){
        DefaultPointcutAdvisor defaultPointcutAdvisor = new DefaultPointcutAdvisor();
        defaultPointcutAdvisor.setPointcut(pointcut);
        defaultPointcutAdvisor.setAdvice(debugInterceptor);
        return defaultPointcutAdvisor;
    }

    @Bean
    public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator(){
        DefaultAdvisorAutoProxyCreator proxyCreator = new DefaultAdvisorAutoProxyCreator();
        proxyCreator.setExposeProxy(true);
        proxyCreator.setProxyTargetClass(true);
//        proxyCreator.set
        return proxyCreator;
    }
}
